Skip to content

Add Neovim floating chat input (:Augment chat-input)#66

Merged
mgmonteleone merged 4 commits into
mainfrom
bot/neovim-floating-chat-input
Jun 9, 2026
Merged

Add Neovim floating chat input (:Augment chat-input)#66
mgmonteleone merged 4 commits into
mainfrom
bot/neovim-floating-chat-input

Conversation

@mgmonteleone

Copy link
Copy Markdown
Collaborator

Closes #61.

What

Adds a new range-aware :Augment chat-input subcommand that opens a centered floating window with a markdown scratch buffer for composing a chat message before sending it. This upstreams a dependency-free, Neovim-gated version of the floating input the issue author shared (their LazyVim gist), reusing the existing chat plumbing.

Behavior

  • Floating window (Neovim only): nvim_open_win with a scratch buffer (buftype=nofile, bufhidden=wipe), markdown filetype, opened in insert mode.
  • Submit: <C-s> (insert/normal) or <CR> (normal) joins the buffer lines, closes the float, and dispatches to the existing chat flow.
  • Cancel: <Esc> (normal) or <C-c> (insert/normal) closes the float without sending.
  • Range-aware: like :Augment chat, invoking from visual mode (or with a range) includes the selected text. On submit the prior visual selection is restored via gv so it is passed through to the chat request.
  • Vim fallback: the floating window requires Neovim; in Vim (or when a message is supplied directly on the command line) it falls back to the standard input() prompt used by :Augment chat, with no change to existing behavior.
  • No third-party dependencies and no default mappings are added.

Changes

  • autoload/augment.vims:CommandChatInput handler + s:ChatInputSubmit callback; wired into command dispatch and completion.
  • autoload/augment/chat.vimaugment#chat#OpenInputWindow plus submit/cancel helpers and buffer-local mappings.
  • README.md, doc/augment.txt, CHANGELOG.md — document the new command.

Validation

  • Headless Neovim smoke test (nvim --headless): verifies the function and completion entry exist, the float opens with a markdown buffer, a multi-line submit invokes the callback with the joined message and closes the window, and cancel closes the window without firing the callback. Result: SMOKE_OK.

Pull Request opened by Augment Code | View session

Add a new range-aware :Augment chat-input subcommand that opens a centered
floating window with a markdown scratch buffer for composing a chat message.
Submitting joins the buffer lines, closes the float, restores the prior mode
(re-selecting a visual range via gv so the selection is passed through), and
dispatches to the existing chat flow.

The floating window is Neovim-only (nvim_open_win). In Vim, the command falls
back to the standard input() prompt used by :Augment chat, with no change to
existing behavior. No third-party dependencies and no default mappings are
added.

Buffer-local mappings: <C-s> (insert/normal) and <CR> (normal) submit; <Esc>
(normal) and <C-c> (insert/normal) cancel.

Update the command completion list, README.md, doc/augment.txt, and CHANGELOG.md.
@mgmonteleone

Copy link
Copy Markdown
Collaborator Author

PR Author Agent

👋 I've got this PR — here's what I'll handle for you:

  • Review feedback — implement suggestions, answer questions, fix what comes up
  • CI failures — I get pinged when checks fail and try to fix them
  • Merge conflicts — bring the PR back up to date when it falls behind
  • Merge gates — watch CI, reviews, and verification
  • Ping you the moment it's ready to merge

Marking it ready and picking reviewers are your call — I'll leave both alone.

Drop a comment anytime!

Note: opened under @mgmonteleone's identity — the org bot lacks PR write access on this repo, so attribution may differ from other automated PRs.

@mgmonteleone mgmonteleone marked this pull request as ready for review June 9, 2026 09:10
@mgmonteleone mgmonteleone self-assigned this Jun 9, 2026
@mgmonteleone

Copy link
Copy Markdown
Collaborator Author

PR Author Agent

✅ Ready for review on 07df2f8:

  • No CI checks are configured on this repo, so none will run.

Reviewer pick is your call — I won't request anyone myself. I'll respond to any review feedback as it comes in (no merge — that stays a human gate).

@johnny2211

Copy link
Copy Markdown

Minor UX thought: if the user switches out of the float (e.g. <C-w>w) it's orphaned with no clear way back. Worth having :Augment chat-input refocus an existing float instead of opening a new one? Avoids losing typed content on accidental focus loss. Not blocking.

@mgmonteleone

Copy link
Copy Markdown
Collaborator Author

PR Author Agent

Good call on the orphaned-float UX. Implemented in f35f72a: augment#chat#OpenInputWindow now checks for an existing valid input window first and, if found, refocuses it (nvim_set_current_win + startinsert) and returns early instead of opening a new float. The existing buffer and its submit callback are preserved, so typed content survives an accidental focus change (e.g. <C-w>w).

Updated the README and :help doc to note the refocus behavior, and extended the headless smoke test to cover it (re-invoking after moving focus away keeps the same window and its content). All checks pass (SMOKE_OK).

@johnny2211 johnny2211 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good.

@mgmonteleone

Copy link
Copy Markdown
Collaborator Author

PR Author Agent

Resolved the merge conflict with main (merge commit 78b1057). The conflict was a CHANGELOG.md overlap with #67's :Augment help entry — both Unreleased bullets are now kept. I also registered chat-input in the new :Augment help command list (added by #67) so it shows up in :Augment help and :Augment help chat-input.

Re-ran the headless Neovim smoke test → SMOKE_OK. PR is mergeable: clean again. No completion/suggestion surface touched.

@johnny2211

Copy link
Copy Markdown

Found during manual QA (CSS-902): whitespace guard misses pure-newline messages.

Repro: :Augment chat-input → press <CR> (or several) → <C-s>. A blank message gets sent instead of being treated as cancel.

Cause: the guard in s:ChatInputSubmit (and s:CommandChat) uses \s, which in Vim regex is [ \t] only — newlines aren't matched.

if a:message ==# '' || a:message =~# '^\s*$'

Fix: swap \s for \_s (whitespace incl. newlines) at both sites:

if a:message ==# '' || a:message =~# '^\_s*$'

The empty-string check is then redundant but harmless. Worth a sub-case in the smoke test (buffer = ["", ""] → expect cancel).

@johnny2211

Copy link
Copy Markdown

Found during manual QA (CSS-902): visual selection is not restored after submit, contrary to PR description.

Repro: open any file, V + jj to select 3 lines, :'<,'>Augment chat-input, type a message, <C-s>. After the float closes, the source buffer has no visual selection — gv was never invoked.

Cause: was_visual is computed from mode() inside s:CommandChatInput, but by then Vim has already left visual mode (the : opened the cmdline), so mode() returns 'n' and was_visual is always false. That false value is passed as the reselect arg to s:ChatInputSubmit, so the normal! gv branch never runs.

let was_visual = index(['v', 'V', "\<C-v>"], mode()) >= 0  " always false here
...
let Callback = function('s:ChatInputSubmit', [source_win, ranged, was_visual])

Fix: drive reselect off ranged instead — when invoked as :'<,'>... the '</'> marks are set and gv works:

let Callback = function('s:ChatInputSubmit', [source_win, ranged, ranged])

(Or simpler: drop the dead was_visual plumbing entirely and have s:ChatInputSubmit reselect whenever a:ranged.)

Worth a smoke-test sub-case: invoke from visual-line mode, submit, assert mode() ==# 'V' afterwards.

Address review feedback (CSS-902):
- Use \_s instead of \s in the empty-message guard (s:ChatInputSubmit and
  s:CommandChat) so a buffer of only newlines/blank lines is treated as cancel
  rather than sending an empty chat message.
- Drive visual reselection off a:ranged instead of the always-false was_visual
  (mode() is already 'n' by the time the command runs), so the '<,'> selection
  is restored via gv on submit as documented.

Extended the headless smoke test with an empty-guard sub-case and a gv
reselection sub-case.
@mgmonteleone

Copy link
Copy Markdown
Collaborator Author

PR Author Agent

Thanks for the QA finds (CSS-902) — both fixed in 629bb0f:

  1. Newline-only submissions now cancel. Swapped \s\_s in the empty-message guard at both sites (s:ChatInputSubmit and s:CommandChat), so a buffer of only blank lines is treated as cancel instead of sending an empty message.
  2. Visual selection restored on submit. Dropped the always-false was_visual plumbing and drive reselection off a:ranged. Since the command leaves visual mode (setting '</'>) before opening the float, gv now works whether invoked from visual mode or via an explicit :'<,'> range.

Extended the headless smoke test with an empty-guard sub-case (blank/newline-only → cancel) and a gv reselection sub-case (asserts mode() ==# 'V' after the visual-exit → gv sequence). Re-ran → SMOKE_OK. Still chat-only; no completion surface touched.

@johnny2211

Copy link
Copy Markdown

Re-tested on 629bb0f (CSS-902) — both fixes confirmed ✅

  • Case 5 (blank-line cancel): empty buffer, spaces-only, and pure-newline submissions all close the float with Chat cancelled. No more blank messages.
  • Case 4 (visual range): V+3j:'<,'>Augment chat-input<C-s> now leaves the source buffer back in -- VISUAL LINE -- with the original 4 lines highlighted. Yank-after-submit returns the full selection.

Rest of the matrix from the previous run was already green. No new issues. 👍

@mgmonteleone

Copy link
Copy Markdown
Collaborator Author

PR Author Agent

@mgmonteleone Ready to merge on 629bb0f:

  • ✅ No CI configured on this repo
  • ✅ Approved by johnny2211 (re-tested the CSS-902 fixes — confirmed)
  • ✅ All review threads addressed
  • mergeable: clean

Holding for the human merge gate — I won't merge automatically.

@johnny2211 johnny2211 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving on 629bb0f after CSS-902 fixes verified (Cases 4 and 5 now PASS). Full QA matrix green. ✅

@mgmonteleone mgmonteleone merged commit 25af149 into main Jun 9, 2026
@mgmonteleone mgmonteleone mentioned this pull request Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin Enhancement

2 participants